package com.yf.yfmovieapp.pojo;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;

public class TimeTransformer {

	/**
	 * 时间戳转换
	 *
	 * @param timestamp 时间戳
	 * @return localdatetime
	 */
	public static LocalDateTime timestamToDatetime(long timestamp) {
		Instant instant = Instant.ofEpochMilli(timestamp);
		return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
	}

	/**
	 * localdatetime转换时间戳
	 *
	 * @param ldt localdatetime
	 * @return 时间戳
	 */
	public static long datatimeToTimestamp(LocalDateTime ldt) {
		long timestamp = ldt.toInstant(ZoneOffset.of("+8")).toEpochMilli();
		return timestamp;
	}
}